home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / WD_SRC.ZIP / SYSTEM / SCREEN.CPP < prev    next >
C/C++ Source or Header  |  1995-01-30  |  17KB  |  849 lines

  1. #include "..\Source\LastWolf.hpp"
  2.  
  3. // Stuff for text display.
  4. char *rom_char_set = (char *)0xF0000; // rom characters 8x8
  5. #define CHAR_HEIGHT 8
  6. #define CHAR_WIDTH 8
  7.  
  8.  
  9. #define VGA_MEM 0xA0000;
  10. char oldScreenMode;
  11.  
  12. BYTE palette[768];
  13.  
  14. BOOL bScreenInitted=FALSE;
  15.  
  16.  
  17. short xPages, xPlanes;  // Used for mode X only
  18. short iWidthBytes;
  19. short curDispPage=0;
  20.  
  21.  
  22. #ifdef MODE_X
  23.  
  24. long MakeModeXDWord( void * );
  25. #pragma aux MakeModeXDWord = \
  26. "mov    al,[ebx+12]"    \
  27. "mov    ah,[ebx+8]"        \
  28. "bswap    eax"            \
  29. "mov    ah,[ebx+4]"        \
  30. "mov al,[ebx]"            \
  31. value [eax]                \
  32. parm [ebx];
  33.  
  34. //4 planes
  35. //1 page
  36. Register Mode360x480[] =
  37.     {
  38.     { 0x3c2, 0x0, 0xe7},
  39.     { 0x3d4, 0x0, 0x6b},
  40.     { 0x3d4, 0x1, 0x59},
  41.     { 0x3d4, 0x2, 0x5a},
  42.     { 0x3d4, 0x3, 0x8e},
  43.     { 0x3d4, 0x4, 0x5e},
  44.     { 0x3d4, 0x5, 0x8a},
  45.     { 0x3d4, 0x6, 0x0d},
  46.     { 0x3d4, 0x7, 0x3e},
  47.     { 0x3d4, 0x8, 0x0},
  48.     { 0x3d4, 0x9, 0x40},
  49.     { 0x3d4, 0x10, 0xea},
  50.     { 0x3d4, 0x11, 0xac},
  51.     { 0x3d4, 0x12, 0xdf},
  52.     { 0x3d4, 0x13, 0x2d},
  53.     { 0x3d4, 0x14, 0x0},
  54.     { 0x3d4, 0x15, 0xe7},
  55.     { 0x3d4, 0x16, 0x06},
  56.     { 0x3d4, 0x17, 0xe3},
  57.     { 0x3c4, 0x1, 0x01},
  58.     { 0x3c4, 0x4, 0x06},
  59.     { 0x3ce, 0x5, 0x40},
  60.     { 0x3ce, 0x6, 0x05},
  61.     { 0x3c0, 0x10, 0x41},
  62.     { 0x3c0, 0x13, 0x00},
  63.     };
  64.  
  65.  
  66. //4 planes
  67. //2 pages
  68. Register Mode360x360[] =
  69.     {
  70.     { 0x3c2, 0x0, 0x67},
  71.     { 0x3d4, 0x0, 0x6b},
  72.     { 0x3d4, 0x1, 0x59},
  73.     { 0x3d4, 0x2, 0x5a},
  74.     { 0x3d4, 0x3, 0x8e},
  75.     { 0x3d4, 0x4, 0x5e},
  76.     { 0x3d4, 0x5, 0x8a},
  77.     { 0x3d4, 0x6, 0xbf},
  78.     { 0x3d4, 0x7, 0x1f},
  79.     { 0x3d4, 0x8, 0x0},
  80.     { 0x3d4, 0x9, 0x40},
  81.     { 0x3d4, 0x10, 0x88},
  82.     { 0x3d4, 0x11, 0x85},
  83.     { 0x3d4, 0x12, 0x67},
  84.     { 0x3d4, 0x13, 0x2d},
  85.     { 0x3d4, 0x14, 0x0},
  86.     { 0x3d4, 0x15, 0x6d},
  87.     { 0x3d4, 0x16, 0xba},
  88.     { 0x3d4, 0x17, 0xe3},
  89.     { 0x3c4, 0x1, 0x01},
  90.     { 0x3c4, 0x4, 0x06},
  91.     { 0x3ce, 0x5, 0x40},
  92.     { 0x3ce, 0x6, 0x05},
  93.     { 0x3c0, 0x10, 0x41},
  94.     { 0x3c0, 0x13, 0x00},
  95.     };
  96.  
  97.  
  98. Register Mode400x600[] =
  99.     {
  100.     { 0x3c2, 0x0, 0xe7},
  101.     { 0x3d4, 0x0, 0x70},
  102.     { 0x3d4, 0x1, 0x63},
  103.     { 0x3d4, 0x2, 0x64},
  104.     { 0x3d4, 0x3, 0x92},
  105.     { 0x3d4, 0x4, 0x65},
  106.     { 0x3d4, 0x5, 0x82},
  107.     { 0x3d4, 0x6, 0x70},
  108.     { 0x3d4, 0x7, 0xf0},
  109.     { 0x3d4, 0x8, 0x0},
  110.     { 0x3d4, 0x9, 0x60},
  111.     { 0x3d4, 0x10, 0x5b},
  112.     { 0x3d4, 0x11, 0x8c},
  113.     { 0x3d4, 0x12, 0x57},
  114.     { 0x3d4, 0x13, 0x32},
  115.     { 0x3d4, 0x14, 0x0},
  116.     { 0x3d4, 0x15, 0x58},
  117.     { 0x3d4, 0x16, 0x70},
  118.     { 0x3d4, 0x17, 0xe3},
  119.     { 0x3c4, 0x1, 0x01},
  120.     { 0x3c4, 0x4, 0x06},
  121.     { 0x3ce, 0x5, 0x40},
  122.     { 0x3ce, 0x6, 0x05},
  123.     { 0x3c0, 0x10, 0x41},
  124.     { 0x3c0, 0x13, 0x00},
  125.     };
  126.  
  127.  
  128.  
  129. Register Mode320x240[] =
  130.     {
  131.     { 0x3c2, 0x0, 0xe3},
  132.     { 0x3d4, 0x0, 0x5f},
  133.     { 0x3d4, 0x1, 0x4f},
  134.     { 0x3d4, 0x2, 0x50},
  135.     { 0x3d4, 0x3, 0x82},
  136.     { 0x3d4, 0x4, 0x54},
  137.     { 0x3d4, 0x5, 0x80},
  138.     { 0x3d4, 0x6, 0xd},
  139.     { 0x3d4, 0x7, 0x3e},
  140.     { 0x3d4, 0x8, 0x0},
  141.     { 0x3d4, 0x9, 0x41},
  142.     { 0x3d4, 0x10, 0xea},
  143.     { 0x3d4, 0x11, 0xac},
  144.     { 0x3d4, 0x12, 0xdf},
  145.     { 0x3d4, 0x13, 0x28},
  146.     { 0x3d4, 0x14, 0x0},
  147.     { 0x3d4, 0x15, 0xe7},
  148.     { 0x3d4, 0x16, 0x6},
  149.     { 0x3d4, 0x17, 0xe3},
  150.     { 0x3c4, 0x1, 0x1},
  151.     { 0x3c4, 0x4, 0x6},
  152.     { 0x3ce, 0x5, 0x40},
  153.     { 0x3ce, 0x6, 0x5},
  154.     { 0x3c0, 0x10, 0x41},
  155.     { 0x3c0, 0x13, 0x0},
  156.     };
  157.  
  158.  
  159.  
  160. Register Mode320x200[] =
  161.     {
  162.     { 0x3c2, 0x0, 0x63},
  163.     { 0x3d4, 0x0, 0x5f},
  164.     { 0x3d4, 0x1, 0x4f},
  165.     { 0x3d4, 0x2, 0x50},
  166.     { 0x3d4, 0x3, 0x82},
  167.     { 0x3d4, 0x4, 0x54},
  168.     { 0x3d4, 0x5, 0x80},
  169.     { 0x3d4, 0x6, 0xbf},
  170.     { 0x3d4, 0x7, 0x1f},
  171.     { 0x3d4, 0x8, 0x0},
  172.     { 0x3d4, 0x9, 0x41},
  173.     { 0x3d4, 0x10, 0x9c},
  174.     { 0x3d4, 0x11, 0x8e},
  175.     { 0x3d4, 0x12, 0x8f},
  176.     { 0x3d4, 0x13, 0x28},
  177.     { 0x3d4, 0x14, 0x0},
  178.     { 0x3d4, 0x15, 0x96},
  179.     { 0x3d4, 0x16, 0xb9},
  180.     { 0x3d4, 0x17, 0xe3},
  181.     { 0x3c4, 0x1, 0x01},
  182.     { 0x3c4, 0x4, 0x06},
  183.     { 0x3ce, 0x5, 0x40},
  184.     { 0x3ce, 0x6, 0x05},
  185.     { 0x3c0, 0x10, 0x41},
  186.     { 0x3c0, 0x13, 0x0},
  187.     };
  188.  
  189.  
  190.  
  191.  
  192. /*  Code from TWEAK  */
  193.  
  194. /*
  195.     readyVgaRegs() does the initialization to make the VGA ready to
  196.     accept any combination of configuration register settings.
  197.  
  198.     This involves enabling writes to index 0 to 7 of the CRT controller
  199.     (port 0x3d4), by clearing the most significant bit (bit 7) of index
  200.     0x11.
  201. */
  202.  
  203. void readyVgaRegs(void)
  204.     {
  205.     int v;
  206.     outp(0x3d4,0x11);
  207.     v = inp(0x3d5) & 0x7f;
  208.     outp(0x3d4,0x11);
  209.     outp(0x3d5,v);
  210.     }
  211.  
  212. /*
  213.     outReg sets a single register according to the contents of the
  214.     passed Register structure.
  215. */
  216.  
  217. void outReg(Register r)
  218.     {
  219.     switch (r.port)
  220.         {
  221.         /* First handle special cases: */
  222.  
  223.         case ATTRCON_ADDR:
  224.             inp(STATUS_ADDR);               /* reset read/write flip-flop */
  225.             outp(ATTRCON_ADDR, r.index | 0x20);
  226.                                         /* ensure VGA output is enabled */
  227.             outp(ATTRCON_ADDR, r.value);
  228.             break;
  229.  
  230.         case MISC_ADDR:
  231.         case VGAENABLE_ADDR:
  232.             outp(r.port, r.value);  /*      directly to the port */
  233.             break;
  234.  
  235.         case SEQ_ADDR:
  236.         case GRACON_ADDR:
  237.         case CRTC_ADDR:
  238.         default:                                                /* This is the default method: */
  239.             outp(r.port, r.index);  /*      index to port                      */
  240.             outp(r.port+1, r.value);/*      value to port+1                    */
  241.             break;
  242.         }
  243.     }
  244.  
  245.  
  246. /*
  247.     outRegArray sets n registers according to the array pointed to by r.
  248.     First, indexes 0-7 of the CRT controller are enabled for writing.
  249. */
  250.  
  251. void outRegArray(Register *r, int n)
  252. {
  253.     readyVgaRegs();
  254.     while (n--)
  255.         outReg(*r++);
  256. }
  257.  
  258.  
  259. BOOL s_SetVideoMode( WORD newVidMode )
  260. {
  261.     DWORD x;
  262.  
  263.     /* Set variables related to screen access  */
  264.     switch( newVidMode )
  265.     {
  266.         case 0:
  267.             xPlanes=4;
  268.             xPages=4;
  269.         
  270.             s_Width = 320;
  271.             s_Height = 200;
  272.             break;
  273.             
  274.         case 1:
  275.             xPlanes=4;
  276.             xPages=4;
  277.         
  278.             s_Width = 320;
  279.             s_Height = 240;
  280.             break;
  281.  
  282.         case 2:
  283.             xPlanes=4;
  284.             xPages=2;
  285.  
  286.             s_Width = 360;
  287.             s_Height = 360;
  288.             break;
  289.         
  290.         case 3:
  291.             xPlanes=4;
  292.             xPages=1;
  293.             
  294.             s_Width=360;
  295.             s_Height=480;
  296.             break;
  297.  
  298.         case 4:
  299.             xPlanes=4;
  300.             xPages=1;
  301.             
  302.             s_Width=400;
  303.             s_Height=600;
  304.             break;
  305.         
  306.         default:
  307.             xPlanes=4;
  308.             xPages=4;
  309.         
  310.             s_Width = 320;
  311.             s_Height = 200;
  312.     }
  313.  
  314.     
  315.     s_SizeBytes = s_Width * s_Height;
  316.     iWidthBytes = s_Width/xPlanes;
  317.  
  318.  
  319. #ifdef DOS
  320.     /* Set VGA BIOS mode 13h: */
  321.     s_SetMode(0x13);
  322.                                                                                                                         
  323.     // Have TWEAK's stuff do the real work
  324.     if( newVidMode == 0 )
  325.         outRegArray( Mode320x200, sizeof(Mode320x200)/sizeof(Register));
  326.     else if( newVidMode == 1 )
  327.         outRegArray( Mode320x240, sizeof(Mode320x240)/sizeof(Register));
  328.     else if( newVidMode == 2 )
  329.         outRegArray( Mode360x360, sizeof(Mode360x360)/sizeof(Register));
  330.     else if( newVidMode == 3 )
  331.         outRegArray( Mode360x480, sizeof(Mode360x480)/sizeof(Register));
  332.     else if( newVidMode == 4 )
  333.         outRegArray( Mode400x600, sizeof(Mode400x600)/sizeof(Register));
  334.     else
  335.         outRegArray( Mode320x200, sizeof(Mode320x200)/sizeof(Register));
  336.             
  337.     // Set our display page to 0
  338.     outp( CRTC_ADDR, 0x0C );
  339.     outp( CRTC_ADDR+1, 0 );
  340.     outp( CRTC_ADDR, 0x0D );
  341.     outp( CRTC_ADDR+1, 0 );       
  342. #endif
  343.     
  344.     // Create the x lookup information.
  345.     s_PagedWidth = iWidthBytes;
  346.     s_PageLookup = new DWORD[s_Width];
  347.  
  348.     for( x=0; x < s_Width; x++ )
  349.         s_PageLookup[x] = ((x % xPlanes) * (s_SizeBytes/xPlanes)) + (x/xPlanes);
  350.  
  351.     return TRUE;
  352. }
  353.  
  354.  
  355. BOOL s_Init()
  356. {
  357.     /*  Init stuff  */
  358. #ifdef DOS
  359.     oldScreenMode = s_GetMode();
  360. #endif
  361.     s_SetVideoMode( videoMode );
  362.  
  363.     pVgaMem = (char *)VGA_MEM;
  364.     pScreenMem = (char *)malloc( s_SizeBytes );
  365.  
  366.     bScreenInitted = TRUE;
  367.  
  368. #ifdef PALETTE_MAPS
  369.     /* Load the palette maps and set the palette */
  370.     if( s_SetPaletteMaps() == FALSE )
  371.         return FALSE;
  372. #endif
  373.  
  374.     return TRUE;
  375. }
  376.  
  377.  
  378. BOOL s_DrawRegion( DWORD x1, DWORD y1, DWORD x2, DWORD y2, DWORD destX, DWORD destY )
  379. {
  380.     DWORD plane;
  381.     DWORD actStart=0, visStart;
  382.     DWORD blitSize, destBlitPos, srcBlitPos;
  383.     DWORD y;
  384.  
  385.     // Get our drawing page right.
  386.     if( xPages > 1 )
  387.     {
  388.         if( curDispPage == 0 )
  389.             actStart = 1 * iWidthBytes * s_Height;
  390.         else
  391.             actStart = 0;
  392.     }
  393.  
  394.     // Get the blit size for a horizontal line.
  395.     blitSize = (x2-x1);
  396.     blitSize = ((blitSize / xPlanes) / 4)+1;
  397.     
  398.     for( plane=0; plane < xPlanes; plane++ )
  399.     {
  400.         outpw( SEQ_ADDR, ( (0x01 << plane << 8)) + 0x02 );
  401.         
  402.         destBlitPos = actStart + (iWidthBytes*destY) + (destX/4);
  403.         //srcBlitPos =  (plane * (s_SizeBytes/xPlanes)) + (y1 * s_PagedWidth) + x1;
  404.         srcBlitPos = s_PageLookup[x1+plane] + (y1*s_PagedWidth);
  405.         for( y=0; y < (y2-y1); y++ )
  406.         {
  407. #ifdef DOS
  408.             s_ScreenBlit( &pVgaMem[destBlitPos], &pScreenMem[srcBlitPos], blitSize );
  409. #endif
  410.             
  411.             destBlitPos += iWidthBytes;
  412.             srcBlitPos += s_PagedWidth;
  413.         }
  414.     }
  415.  
  416.     //  Right now this just swaps between page 0 and 1. 
  417.     // Set our display page to the one we just drew on.
  418.     if( xPages > 1 )
  419.     {
  420.         if( curDispPage == 0 )
  421.             curDispPage = 1;
  422.         else
  423.             curDispPage = 0;
  424.  
  425.         visStart = curDispPage * iWidthBytes * s_Height;
  426. #ifdef DOS
  427.         outp( CRTC_ADDR, 0x0C );
  428.         outp( CRTC_ADDR+1, visStart >> 8 );
  429.         outp( CRTC_ADDR, 0x0D );
  430.         outp( CRTC_ADDR+1, visStart & 0xFF );       
  431. #endif
  432.     }
  433.     return TRUE;
  434. }
  435.  
  436.  
  437. BOOL s_Draw()
  438. {
  439. #ifdef DOS
  440.     DWORD plane;
  441.     DWORD actStart=0, visStart;
  442.     DWORD blitSize;
  443.     
  444.     // Get our drawing page right.
  445.     if( xPages > 1 )
  446.     {
  447.         if( curDispPage == 0 )
  448.             actStart = 1 * iWidthBytes * s_Height;
  449.         else
  450.             actStart = 0;
  451.     }
  452.  
  453.     blitSize = (s_SizeBytes/xPlanes)/4;
  454.     for( plane=0; plane < xPlanes; plane++ )
  455.     {
  456.         outpw( SEQ_ADDR, ( (0x01 << plane << 8)) + 0x02 );
  457.         
  458.         s_ScreenBlit( &pVgaMem[actStart], &pScreenMem[plane * (s_SizeBytes/xPlanes)], blitSize );
  459.     }
  460.  
  461.     //  Right now this just swaps between page 0 and 1. 
  462.     // Set our display page to the one we just drew on.
  463.     if( xPages > 1 )
  464.     {
  465.         if( curDispPage == 0 )
  466.             curDispPage = 1;
  467.         else
  468.             curDispPage = 0;
  469.  
  470.         visStart = curDispPage * iWidthBytes * s_Height;
  471.         outp( CRTC_ADDR, 0x0C );
  472.         outp( CRTC_ADDR+1, visStart >> 8 );
  473.         outp( CRTC_ADDR, 0x0D );
  474.         outp( CRTC_ADDR+1, visStart & 0xFF );       
  475.     }
  476. #endif
  477.     return TRUE;
  478. }
  479.  
  480.  
  481. void sX_SetPixel( short x, short y, char color )
  482. {
  483.     long actStart;
  484.  
  485.     if( curDispPage == 0 )
  486.         actStart = 0;
  487.     else
  488.         actStart = 1 * iWidthBytes * s_Height;
  489.  
  490.     outp( SEQ_ADDR, 0x02 );
  491.     outp( 0x3C5, 0x01 << (x & 3) );
  492.     
  493.     pVgaMem[ (unsigned)(iWidthBytes * y) + (x / xPlanes) + actStart] = color;
  494. }
  495.  
  496.  
  497. // End of MODE X ifdef thing
  498. #endif
  499.  
  500.  
  501.  
  502. #ifndef MODE_X
  503. BOOL s_Init()
  504. {
  505.     WORD x;
  506.     
  507.     bScreenInitted = TRUE;
  508.     
  509.     /* Set variables related to screen access  */
  510.     s_Width = 320;
  511.     s_Height = 200;
  512.     s_SizeBytes = (long)s_Width * (long)s_Height;
  513.  
  514.     /*  Init stuff  */
  515.     pVgaMem = (char *)VGA_MEM;
  516.     pScreenMem = new BYTE[s_SizeBytes];
  517.  
  518.     // Create the x lookup information.
  519.     s_PagedWidth = s_Width;
  520.     s_PageLookup = new WORD[s_Width];
  521.     for( x=0; x < s_Width; x++ )
  522.         s_PageLookup[x] = x;
  523.     
  524. #ifdef DOS
  525.     oldScreenMode = s_GetMode();
  526.  
  527.     /* Set VGA BIOS mode 13h: */
  528.     s_SetMode(0x13);
  529. #endif
  530.  
  531. #ifdef PALETTE_MAPS    
  532.     /* Load the palette maps and set the palette */
  533.     if( s_SetPaletteMaps() == FALSE )
  534.         return FALSE;
  535.  
  536. #ifdef DOS
  537.     s_SetPalette( palette );
  538. #endif
  539. #endif
  540.  
  541.     return TRUE;
  542. }
  543.  
  544.  
  545. BOOL s_Draw()
  546. {
  547. #ifdef DOS
  548.     s_WaitForRetrace();
  549.     s_ScreenBlit( pVgaMem, pScreenMem, 16000 );
  550. #endif
  551.         
  552.     return TRUE;
  553. }
  554.  
  555. #endif
  556.  
  557.  
  558. BOOL s_UnInit( BOOL bDeleteMaps )
  559. {
  560.     short i;
  561.  
  562.     delete s_PageLookup;
  563.  
  564.     if( bDeleteMaps )
  565.     {
  566.            // Get rid of the palette map.
  567.            for( i=0; i < nPaletteMaps; i++ )
  568.             delete pPaletteMaps[i];
  569.     
  570.            delete pPaletteMaps;
  571.     }
  572.  
  573. #ifdef DOS
  574.        // Set the original screen mode.
  575.        s_SetMode( oldScreenMode );
  576. #endif
  577.  
  578.     free( pScreenMem );
  579.     
  580.     return TRUE;
  581. }
  582.  
  583.  
  584. BOOL s_Clear( BYTE fillWith )
  585. {
  586.     s_DWordMemSet( pScreenMem, fillWith, s_SizeBytes>>2 );
  587.  
  588.     return TRUE;
  589. }
  590.  
  591. BOOL s_ClearHalf( BYTE fillWith )
  592. {
  593.     s_DWordMemSet( &pVgaMem[s_SizeBytes>>1], fillWith, (s_SizeBytes>>3) );
  594.  
  595.     return TRUE;
  596. }
  597.  
  598.  
  599. void ResetVideoMode(WORD mode)
  600. {
  601.     if( mode >= 0 && mode < 5 )
  602.         videoMode = mode;
  603.  
  604.     delete s_PageLookup;
  605.     delete pScreenMem;
  606.     s_SetVideoMode( videoMode );
  607.     pScreenMem = new BYTE[s_SizeBytes];
  608.                     
  609. #ifdef DOS
  610.     s_SetPalette( curLevel.palette );
  611. #endif
  612.  
  613.     // Reset the viewing parameters.
  614.     s_MinY = 0;
  615.     s_MaxY = s_Height;
  616.     s_MinX = 0;
  617.     s_MaxX = s_Width;
  618.     s_DrawWidth = s_Width;
  619.     s_DrawHeight = s_Height;
  620. }
  621.  
  622.  
  623. #ifdef DOS
  624.  
  625.  
  626. void s_BlitChar(int xc,int yc,char c,int color,int trans_flag)
  627. {
  628. // this function uses the rom 8x8 character set to blit a character on the
  629. // video screen, notice the trick used to extract bits out of each character
  630. // byte that comprises a line
  631.  
  632.     int offset,x,y;
  633.     char *work_char;
  634.     unsigned char bit_mask = 0x80;
  635.  
  636.     // compute starting offset in rom character lookup table
  637.     work_char = rom_char_set + (0xFA6EL) + c * CHAR_HEIGHT;
  638.  
  639.     // compute offset of character in video buffer
  640.     offset = (yc * s_PagedWidth);
  641.  
  642.     for (y=0; y<CHAR_HEIGHT; y++)
  643.     {
  644.         // reset bit mask
  645.         bit_mask = 0x80;
  646.  
  647.         for (x=0; x<CHAR_WIDTH; x++)
  648.         {
  649.             // test for transparent pixel i.e. 0, if not transparent then draw
  650.             if ((*work_char & bit_mask))
  651.                  pScreenMem[offset + s_PageLookup[x + xc]] = color;
  652.             else if (!trans_flag)  // takes care of transparency
  653.                 pScreenMem[offset + s_PageLookup[x + xc]] = 0;
  654.  
  655.             // shift bit mask
  656.             bit_mask = (bit_mask>>1);
  657.         }
  658.  
  659.         // move to next line in video buffer and in rom character data area
  660.         offset += s_PagedWidth;
  661.         work_char++;
  662.     }
  663.  
  664. } // end Blit_Char
  665.  
  666.  
  667. void s_BlitString(int x,int y,int color, char *string,int trans_flag)
  668. {
  669. // this function blits an entire string on the screen with fixed spacing
  670. // between each character.  it calls blit_char.
  671.  
  672.     int index;
  673.  
  674.     for (index=0; string[index]!=0; index++)
  675.      s_BlitChar(x+(index<<3),y,string[index],color,trans_flag);
  676.  
  677. } /* end Blit_String */
  678.  
  679.  
  680. void s_SetMode( char modeNum )
  681. {
  682.     union REGS regs;
  683.     
  684.     regs.h.al = modeNum;
  685.     regs.h.ah = 0;
  686.     int386( 0x10, ®s, ®s );      
  687. }
  688.  
  689.  
  690. char s_GetMode()
  691. {
  692.     union REGS regs;
  693.     struct SREGS sregs;
  694.  
  695.  
  696.     segread( &sregs );
  697.  
  698.     regs.h.ah = 0x0F;
  699.     int386x( 0x10, ®s, ®s, &sregs );
  700.  
  701.     return regs.h.al;        
  702. }
  703.                         
  704.  
  705. BOOL s_SetPalette( char *palette )
  706. {
  707.     int i;
  708.  
  709.     /*  Wait for retraces  */
  710.     s_WaitForRetrace();
  711.  
  712.     /*  Dump the buffer to the card  */
  713.     outp( 0x3C8, 0x0 );
  714.     for( i=0; i < 768; i++ )
  715.         outp( 0x3C9, palette[i] );
  716.     
  717.     return TRUE;
  718. }
  719.  
  720.  
  721. BOOL s_Alert( char *message )
  722. {
  723.     printf(message);
  724.     
  725.     return TRUE;        
  726. }
  727.  
  728.  
  729. void s_WaitForRetrace()
  730. {
  731.     while( (inp(0x3DA) & 8) != 0 );
  732.     while( (inp(0x3DA) & 8) == 0 );
  733. }
  734.  
  735. #else //(#ifdef DOS)
  736.  
  737. // Dummy version of functions so the same code will work..
  738. void s_BlitChar(int xc,int yc,char c,int color,int trans_flag)
  739. {
  740.     xc=xc;
  741.     yc=yc;
  742.     c=c;
  743.     color=color;
  744.     trans_flag=trans_flag;
  745. }
  746.  
  747. void s_BlitString(int x,int y,int color, char *string,int trans_flag)
  748. {
  749.     x=x;
  750.     y=y;
  751.     color=color;
  752.     string=string;
  753.     trans_flag=trans_flag;
  754. }
  755.  
  756. #endif    // End of an #ifdef DOS.
  757.  
  758.  
  759. #pragma aux s_ScreenBlit = \
  760. "START_COPY:"   \
  761. "lodsd" \
  762. "stosd" \
  763. "loopnz START_COPY" \
  764. modify [eax]    \
  765. parm [edi] [esi] [cx];
  766.  
  767. #pragma aux s_DWordMemSet = \
  768. "mov bl,al" \
  769. "mov ah,al" \
  770. "bswap eax" \
  771. "mov al,bl" \
  772. "mov ah,bl" \
  773. "repnz stosd"   \
  774. modify [eax bl] \
  775. parm [edi] [al] [ecx];
  776.     
  777.  
  778.  
  779. BOOL s_SetPixel( WORD x, WORD y, BYTE color )
  780. {
  781.     long drawPos;
  782.  
  783.  
  784.     if( x < s_Width && x >= 0 && y < s_Height && y >= 0 )
  785.     {
  786.         drawPos = (y*s_PagedWidth) + s_PageLookup[x];
  787.     
  788.         pScreenMem[drawPos] = color;
  789.         return TRUE;
  790.     }
  791.  
  792.     return FALSE;
  793. }
  794.  
  795.  
  796. BOOL s_SetPaletteMaps()
  797. {
  798.     FILE *fp;
  799.     short i, j, tempColor;
  800.     
  801.     
  802.     if( (fp = fopen(PALETTE_MAP, "r")) == NULL )
  803.     {
  804.         nPaletteColors=0;
  805.         nPaletteMaps=0;
  806.         pPaletteMaps = NULL;
  807.         
  808.         return FALSE;
  809.     }
  810.  
  811.     fscanf( fp, "%hd", &nPaletteColors );
  812.     fscanf( fp, "%hd", &nPaletteMaps );
  813.  
  814.     // Read the palette in.
  815.     for( i=0; i < nPaletteColors; i++ )
  816.     {
  817.         fscanf( fp, "%hd", &tempColor );
  818.         palette[i*3] = (BYTE)tempColor;
  819.  
  820.         fscanf( fp, "%hd", &tempColor );
  821.         palette[i*3+1] = (BYTE)tempColor;
  822.  
  823.         fscanf( fp, "%hd", &tempColor );
  824.         palette[i*3+2] = (BYTE)tempColor;
  825.     }
  826.  
  827.     // Set all the extra colors to black
  828.     for( i = nPaletteColors; i < 256; i++ )
  829.         palette[i*3] = palette[i*3+1] = palette[i*3+2] = 0;
  830.  
  831.     // Read the alternate palettes in
  832.     pPaletteMaps = (char **)malloc( sizeof(char *) * nPaletteMaps );
  833.     for( i=0; i < nPaletteMaps; i++ )
  834.     {
  835.         pPaletteMaps[i] = (char *)malloc( sizeof(char) * 256 );
  836.  
  837.         for( j=0; j < nPaletteColors; j++ )
  838.             fscanf( fp, "%hd", &pPaletteMaps[i][j] );
  839.  
  840.         for( j=nPaletteColors; j < 256; j++ )
  841.             pPaletteMaps[i][j] = 0;
  842.     }
  843.  
  844.     fclose(fp);
  845.  
  846.     return TRUE;
  847. }
  848.  
  849.